/**
 * Alibaba.com.cn Inc.
 * Copyright (c) 2004-2021 All Rights Reserved.
 */
package com.yongbao.controller;

import com.yongbao.common.WebResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.dromara.x.file.storage.core.FileInfo;
import org.dromara.x.file.storage.core.FileStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zhanghong
 * @version FileController.java, v 0.1 2023/6/26 21:12 下午 FileController Exp $$
 */
@Slf4j
@RestController
@RequestMapping("/file")
@Api(tags = {"文件模块"})
public class FileController {

    @Autowired
    private FileStorageService fileStorageService;

    @ApiOperation(value = "上传", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/upload")
    public WebResponse<String> upload(MultipartFile file, String module) {
        // 1.上传文件
        String originalFilename = file.getOriginalFilename();
        FileInfo upload = fileStorageService.of(file)
                .upload();
        return WebResponse.build(upload.getUrl());
    }
}
